import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;


public class MainPlayerController 
{
	private MainPlayerView mv;
	private MainPlayerModel mm;
	private boolean hasUserPressedNext;
	
	public MainPlayerController(MainPlayerView mv, MainPlayerModel mm)
	{
		this.mv = mv;
		this.mm = mm;
		hasUserPressedNext = false;
		mv.addNextButtonListener(new nextButtonListener());
	}
	
	public void addCash(double cash)
	{
		mm.addToCash(cash);
	}
	
	public boolean hasUserPressedNext()
	{
		return hasUserPressedNext;
	}
	
	private class nextButtonListener implements ActionListener
	{	
		public void actionPerformed(ActionEvent e) 
		{
			mm.setPartyMembers(mv.getPartyMembersNames());
			String playerName = mv.getMainPlayerName();
			
			if(playerName.equals(""))
			{
				JOptionPane.showMessageDialog(new JFrame("Important!"),
						"You must choose a name for the leader!");
				return;
			}
			
			mm.setName(playerName);
			
			int index = mv.getProfessionIndex();
			
			if(index == -1)
			{
				JOptionPane.showMessageDialog(new JFrame("Important!"),
						"You must select a profession!");
				return;
			}
			
			mm.setProfession(index);
			//mm.getTotalCash();
			//mm.calcInitialCash();
			hasUserPressedNext = true;
		}

	}
}
